package com.hr.剑指offer.work2;

import java.util.Arrays;
import java.util.Collections;

/**
 * @author ：zhz
 * @date ：Created in 2020/12/04
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 * @description: 寻找两个正序数组的中位数
 **/
public class FindMedianSortedArrays_4 {
    public static double findMedianSortedArrays(int[] nums1, int[] nums2) {
        int[] tmp=new int[nums1.length+nums2.length];
        double res;
        for (int i = 0; i < nums1.length; i++) {
            tmp[i]=nums1[i];
        }
        for (int j = 0; j < nums2.length; j++) {
            tmp[nums1.length+j]=nums2[j];
        }
        Arrays.sort(tmp);
        System.out.println(Arrays.toString(tmp));
        System.out.println(tmp.length%2==0);
        if (tmp.length%2==0){//6/3=2
            int left=tmp.length / 2 - 1;
            int right=  tmp.length / 2;
            res=((double)(tmp[left]+tmp[right]))/2;
        }else {
            res=(double)(tmp.length/2);
        }
        return res;
    }

    public static void main(String[] args) {
        int[] nums1={1,3};
        int[] nums2={2};
        System.out.println(FindMedianSortedArrays_4.findMedianSortedArrays(nums1, nums2));
    }
}
